package com.ruoyi.api.controller.moon;

import com.ruoyi.common.annotation.EventTracking;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.moon.domain.MoonCompany;
import com.ruoyi.moon.domain.MoonPosition;
import com.ruoyi.moon.domain.SysRegion;
import com.ruoyi.moon.domain.dto.CityDTO;
import com.ruoyi.moon.domain.dto.ProvinceDTO;
import com.ruoyi.moon.domain.vo.CityVo;
import com.ruoyi.moon.domain.vo.RegionVo;
import com.ruoyi.moon.domain.vo.ReviewsInfoVO;
import com.ruoyi.moon.service.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/moon/index")
public class ApiMoonIndexController extends BaseController {

    @Autowired
    private IMoonCompanyService moonCompanyService;
    @Autowired
    private IMoonReviewsService moonReviewsService;
    @Autowired
    private IMoonUpvoteService moonUpvoteService;
    @Autowired
    ICityService iCityService;
    @Autowired
    private ISysRegionService regionService;
    @Autowired
    private IMoonPositionService moonPositionService;
    /**
     * 查看公司列表
     * @param moonCompany
     * @return
     */
    @GetMapping("/getCompanyList")
    public TableDataInfo list(MoonCompany moonCompany)
    {
        startPage();
        List<MoonCompany> list = moonCompanyService.selectMoonCompanyList(moonCompany);
        return getDataTable(list);
    }

    /**
     * 根据公司名称查公司
     * @param companName
     * @return
     */
    @GetMapping("/getCompany")
    public TableDataInfo list(String companName)
    {
        startPage();
        List<MoonCompany> list = moonCompanyService.selectMoonCompanyName(companName);
        for (MoonCompany company : list) {
            if (company.getCompanyRating() == null) {
                company.setCompanyRating(0.0);
            }
        }
        return getDataTable(list);
    }


    /**
     * 查看公司详情
     * @param id
     * @return
     */
    @GetMapping(value = "/getCompanyInfo/{id}")
    @EventTracking(tables = "moon_company",event = "查看公司")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(moonCompanyService.selectMoonCompanyById(id));
    }


    /**
     * 获取评论详细信息 (公司id)
     */
    @GetMapping(value = "/getReviewsInfo/{id}")
    public TableDataInfo getReviewsInfo(@PathVariable("id") Long id)
    {    startPage();
        List<ReviewsInfoVO> ReviewsInfo = moonReviewsService.selectReviewsInfo(id);
        return getDataTable(ReviewsInfo);
    }



    @ApiOperation("省市二级联动")
    @GetMapping("/address")
    public AjaxResult listForIndex() {
        List<ProvinceDTO> list = iCityService.selectCityInfo();
        System.out.println(list);
        return AjaxResult.success(list);
    }


    @ApiOperation("查询省")
    @GetMapping("/pro")
    public AjaxResult listForPro() {
        List<ProvinceDTO> list = iCityService.selectPro();
        System.out.println(list);
        return AjaxResult.success(list);
    }


    @ApiOperation("查询市")
    @GetMapping("/city/{regiConode}")
    public AjaxResult listForCity(@PathVariable("regiConode") String regiConode) {
        List<CityDTO> list = iCityService.selectCity(regiConode);
        System.out.println(list);
        return  AjaxResult.success(list);
    }

    /**
     * 热门城市
     * @return
     */
    @GetMapping("/getPopular")
    public AjaxResult getPopular(){
        List<RegionVo> regions = regionService.selectPopularList();
        return AjaxResult.success(regions);
    }

    @GetMapping("/getCity")
    public AjaxResult getCity(String regionName){
        List<CityVo> citys = regionService.getCity(regionName);
        return AjaxResult.success(citys);
    }

    /**
     * 查询职位管理列表
     */
    @GetMapping("/zhiWei")
    public AjaxResult list(MoonPosition moonPosition)
    {
        List<MoonPosition> list = moonPositionService.selectMoonPositionList(moonPosition);
        return AjaxResult.success(list);
    }

    /**
     * PC端获取公司一条评论
     */
    @GetMapping("/list")
    public TableDataInfo getCompanyReviews(MoonCompany moonCompany)
    {
        startPage();
        List<MoonCompany> list = moonCompanyService.selectMoonCompanyReviewsList(moonCompany);
        return getDataTable(list);
    }


}
